package com.hkbigdata.sybx.mapper;

import com.hkbigdata.sybx.bean.UserProfile;
import com.sun.org.glassfish.gmbal.ManagedObject;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author yangjing
 * @creat 2025-06-04-10:25
 * @email 3010335359@qq.com
 */
@Mapper
public interface UserProfileMapper {

    /**
     * 添加用户资料
     */
    @Insert("INSERT INTO user_profile (name, gender, birthday, signature, user_id) " +
            "VALUES (#{name}, #{gender}, #{birthday}, #{signature}, #{userId})")
    int addUserProfile(UserProfile profile);

    /**
     * 更新用户资料
     */
    @Update("UPDATE user_profile " +
            "SET name = #{name}, " +
            "gender = #{gender}, " +
            "birthday = #{birthday}, " +
            "signature = #{signature} " +
            "WHERE user_id = #{userId}")
    int updateUserProfile(UserProfile profile);

    /**
     * 通过userId查询用户资料
     */
//    @Select("SELECT * FROM user_profile WHERE user_id = #{userId}")
    @Select("SELECT name as name, gender as gender, birthday as birthday, " +
            "signature as signature, user_id as userId " +
            "FROM user_profile where user_id = #{userId}")
    UserProfile getUserProfileByUserId(String userId);


    /**
     * 根据用户ID获取用户名
     * @param userId 用户ID
     * @return 包含 user_id 和 name 的 Map
     */
    @Select("SELECT user_id, name FROM user_profile WHERE user_id = #{userId}")
    Map<String, Object> getUserNameById(String userId);
    /*
    * 查看全部用户资料
    * */
    @Select("SELECT name, gender, birthday, signature, user_id as userId FROM user_profile")
    List<UserProfile> getAllProfiles();
}
